var btnPurid = "";
$(function () {
    //显示按钮
    showPurWiewBtn();
    $.ajaxSetup( {
        //设置ajax请求结束后的执行动作
        complete :
            function(XMLHttpRequest, textStatus) {
                // 通过XMLHttpRequest取得响应头，sessionstatus
                var sessionstatus = XMLHttpRequest.getResponseHeader("sessionstatus");
                if (sessionstatus == "TIMEOUT") {
                    var win = parent.window;
                    while (win != win.top){
                        win = win.top;
                    }
                    win.location.href= XMLHttpRequest.getResponseHeader("CONTEXTPATH");
                }
            }
    });

    //时间选择器
    if( $(".form_date").length>0){
        $(".form_date").datetimepicker({
            language:  'zh-CN',
            weekStart: 1,
            todayBtn:  1,
            autoclose: 1,
            todayHighlight: 1,
            startView: 2,
            minView: 2,
            forceParse: 0
        });
    }

})

$(window).scroll(function () {
    pageInitModule.setScrollToTop();
});

var pageInitModule = (function (mod) {
    mod.setScrollToTop = function () {
        var top = $(window).scrollTop();
        if (top < 60) {
            $('#goTop').hide();
        } else {
            $('#goTop').show();
        }
    }

    return mod;
})(window.pageInitModule || {});

function getQueryString(name) {
    var reg = new RegExp("(^|&)" + name + "=([^&]*)(&|$)", "i");
    var r = window.location.search.substr(1).match(reg);
    if (r != null) return unescape(r[2]); return null;
}

function GetRequest() {
    var url = location.search; //获取url中"?"符后的字串
    var theRequest = new Object();
    if (url.indexOf("?") != -1) {
        var str = url.substr(1);
        var strs = str.split("&");
        for(var i = 0; i < strs.length; i ++) {
            theRequest[strs[i].split("=")[0]]=unescape(strs[i].split("=")[1]);
        }
    }
    return theRequest;
}

//失去焦点判断是否为空
function onBlurValue(obj) {
    var info = $(obj).val();
    if(info!=null&&info!=""){
        $(obj).next().hide();
    }else {
        $(obj).next().show();
    }

}

function checkValue(infoId) {
    var b = true;
    var info = $("#"+infoId).val();
    if(info!=null&&info!=""){
        $("#"+infoId).next().hide();
    }else {
        $("#"+infoId).next().show();
        b = false;
    }

    return b;
}

function promptDail(infos, url) {
    dialog({
        title: '提示信息',
        width: "300px",
        content: infos,
        okValue: '确定',
        ok: function () {
            if(url!=null&&url!=""){
                window.location.href=url;
            }
        }
    }).showModal();
}

function errorDail(infos,url) {
    dialog({
        title: '错误信息',
        width: "300px",
        content: infos,
        okValue: '确定',
        ok: function () {
            if(url!=null&&url!=""){
                window.location.href=url;
            }
        }
    }).showModal();
}


function okDail(infos,url) {
    dialog({
        title: '成功',
        width: "300px",
        content: infos,
        okValue: '确定',
        ok: function () {
            if(url!=null&&url!=""){
                window.location.href=url;
            }
        }
    }).showModal();
}

function showPurWiewBtn() {
    btnPurid = getQueryString("btnPurid");
    if(btnPurid!=null&&btnPurid!=""){
        $.post("/main/getResBtn.do",{"parentId":btnPurid},function (data) {
            if(data!=null&&data.length>0){
                for(var i=0;i<data.length;i++){
                    $("#"+data[i].url).show();
                }
            }
        },"json")
    }
}

